#include <iostream>

using namespace std;

const int N=100;

int ap[N],as[N],al[N],ab[N];

int length(int i){
    int k=1,t = i/2;
    while(t>0){
    ++k;
    t=t/2;
    }
    return k;
}

void Compress(int n,int* p,int *s,int *l,int *b)
{
    int Lmax = 256,head = 11;
    s[0] = 0;
    for(int i =1;i<=n;++i){
        b[i]=length(p[i]);
        int bmax = b[i];
        s[i] = s[i-1] + bmax;
        l[i] = 1;
        for(int j=2;j<=i&&j<=Lmax;++j){
            if(bmax < b[i-j+1]) bmax = b[i-j+1];
            if(s[i]>s[i-j]+j*bmax){
                s[i] = s[i-j]+j*bmax;
                l[i] = j;
            }
        }
        cout<<l[i]<<endl;
        s[i] += head;
    }
}

void Traceback(int n,int &i,int *s,int *l)
{
    if(n==0) return ;
    Traceback(n-l[n],i,s,l);
    s[i++] = n-l[n];
}

void Output(int *s,int *l,int *b,int n){
    cout<<"The optimal value is "<<s[n]<<endl;
    int m = 0;
    Traceback(n,m,s,l);
    s[m] = n;
    cout<<"Decompose into "<<m<<" segment"<<endl;
    for(int j=1;j<=m;++j){
        l[j] = l[s[j]];
        b[j] = b[s[j]];
    }
    for(int j=1;j<=m;++j){
        cout<<l[j]<<' '<<b[j]<<endl;
    }
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>ap[i];
    }
    Compress(n,ap,as,al,ab);
    Output(as,al,ab,n);
    return 0;
}